package com.base.base

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

abstract class IActivity : AppCompatActivity(){

    // 布局资源文件
    protected abstract val layoutRes: Int

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(layoutRes)
        initLayout(savedInstanceState)
        initLayout()
        initListener()
    }

    /**
     * 初始化布局
     */
    protected open fun initLayout(bundle: Bundle?){}
    protected open fun initLayout(){}

    /**
     * 初始化监听器
     */
    protected open fun initListener(){}


    /**
     * 重写窗口请求回调 使回调能传递到fragment中
     */
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        val fragments = supportFragmentManager.fragments
        for (fragment in fragments) fragment.onActivityResult(requestCode, resultCode, data)
    }
}